package com.huluobo.hyj.hyjmodel.widet

import androidx.fragment.app.Fragment
import com.huluobo.hyj.hyjmodel.R
import com.huluobo.hyj.hyjmodel.ui.fragment.ContractFragment
import com.huluobo.hyj.hyjmodel.ui.fragment.ConversationFragment
import com.huluobo.hyj.hyjmodel.ui.fragment.DynamicFragment

//私有构造方法，类似于单例模式的创建
class FragmentFactory private constructor() {

    //三个fragment
    private val conversation by lazy {
        ConversationFragment()
    }
    private val contact by lazy {
        ContractFragment()
    }
    private val dynamic by lazy {
        DynamicFragment()
    }


    //一个伴生对象   返回自身类
    companion object {
        val instance = FragmentFactory()
    }

    //可以在返回值这里加？  可以为null
    fun  setFragment(tabId:Int):Fragment?{
       when(tabId){
            R.id.tab_conversation -> return conversation
            R.id.tab_contacts -> return contact
            R.id.tab_dynamic -> return dynamic
        }
        return null
    }

}